package com.xxl.job.executor.sample.frameless.test.wait_notifyDemo;

public class Demo2 {
    final static Object object = new Object();

    public static void main(String[] args) throws InterruptedException {
        new Thread(() -> {
            synchronized (object) {
                System.out.println(Thread.currentThread().getName() + ":执行。。。");
                try {
                    object.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + ":其它代码。。。");
            }
        },"t1").start();
        new Thread(() -> {
            synchronized (object) {
                System.out.println(Thread.currentThread().getName() + ":执行。。。");
                try {
                    object.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + ":其它代码。。。");
            }
        },"t2").start();
        Thread.sleep(500);
        System.out.println(Thread.currentThread().getName() + ":唤醒object上其它线程");
        synchronized (object) {
            object.notifyAll();
        }
    }


}
